package roborally.Conditions;
import roborally.*;

/**
 * A class of Wall-conditions for playing the roborally game, involving static final wall.
 * 
 * @version  2.90
 * @author   Michiel Ruelens & Dieter Naten
 */
public class Wall extends Condition {

	private static final Wall w = new Wall();
	
	/**
	 * Create a new Wall condition. This condition is only applicable to robots 
	 * and will return true if there is a wall to the right of the robot.
	 */
	private Wall(){
		this.setStringForm("Wall");
	}

	/**
	 * There is no need to have duplicate objects of this class, so only 1 is being created and always returned by this method.
	 */
	@Override
	public Wall getInstance() {
		return w;
	}
	
	/**
	 * Returns true if and only if there is a wall to the right of the robot.
	 * @pre		This condition is only applicable to robots because there is no other placeable with an orientation.
	 */
	@Override
	public boolean validate(Placeable placeable) {
		assert(placeable instanceof Robot);
		boolean result = false;
		Coordinate c = placeable.getCoordinate();
		Board b = placeable.getBoard();
		Orientation o = Orientation.convertIntToOrientation(((Robot) placeable).getOrientation());
		Coordinate coordinateToRight = Coordinate.getCoordinateToRight(c, b, o);
		if(b.hasWallAtPosition(coordinateToRight.getX(), coordinateToRight.getY())){
			result = true;
		}
		return result;
	}


}
